<template>
  <a-table :data="data" style="margin-top: 30px"
           :pagination="{pageSize:searchParams.pageSize,current:searchParams.current,total:total,showTotal:true}"
           @page-change="onPageChange"
  >
    <template #columns>
      <a-table-column title="提交号" data-index="id"></a-table-column>
      <a-table-column title="问题" data-index="title"></a-table-column>
      <a-table-column title="状态">
        <template #cell="{record}">
          <a-space>
            <a-tag checkable v-if="record.status===0" color="green">等待中</a-tag>
            <a-tag checkable v-if="record.status===1" color="green">判题中</a-tag>
            <a-tag checkable v-else-if="record.status===2" color="red">成功</a-tag>
            <a-tag checkable v-else-if="record.status===3" color="#ffb400">失败
            </a-tag>
          </a-space>
        </template>
      </a-table-column>
      <a-table-column title="结果">
        <template #cell="{record}">
          <a-space>
            <a-tag checkable v-if="record.judgeInfo.message==='Accepted'" color="green">Accepted</a-tag>
            <a-tag checkable v-else-if="record.judgeInfo.message==='Wrong Answer'" color="red">Wrong Answer</a-tag>
            <a-tag checkable v-else-if="record.judgeInfo.message==='Memory Limit Exceeded'" color="red">Memory Limit Exceeded</a-tag>
            <a-tag checkable v-else-if="record.judgeInfo.message==='Time Limit Exceeded'" color="yellow">Time Limit Exceeded</a-tag>
            <a-tag checkable v-else-if="record.judgeInfo.message==='System Error'" color="#ffb400">System Error
            </a-tag>
            <a-tag checkable v-else color="#ff7d00
">Runtime Error
            </a-tag>
          </a-space>
        </template>
      </a-table-column>
      <a-table-column title="语言" data-index="language"></a-table-column>
      <a-table-column title="内存">
        <template #cell="{record}">
          {{ record.judgeInfo?.memory == null ? 0 + ' KB' : (record.judgeInfo?.memory) + ' KB' }}
        </template>
      </a-table-column>

      <a-table-column title="时间">
        <template #cell="{record}">
          {{ record.judgeInfo?.time == null ? 0 + ' ms' : (record.judgeInfo?.time) + ' ms' }}
        </template>
      </a-table-column>

      <a-table-column title="提交时间" data-index="createTime"></a-table-column>
    </template>

  </a-table>
</template>


<script setup lang="ts">
import {onMounted, ref, watchEffect} from "vue";
import {QuestionControllerService} from "../../generated";


let data = ref([])
let total = ref();
const searchParams = ref({
  pageSize: 10,
  current: 1
})
const listPageData = async () => {
  const res = await QuestionControllerService.listQuestionSubmitByPageUsingPost(searchParams.value)
  data.value = res.data.records
  total.value = res.data.total
  console.log('questionSubmitList::::', res)
}


//分页方法
const onPageChange = (page: number) => {
  // searchParams.value.current =page
  searchParams.value = {
    ...searchParams.value,//把原来的值复制过来
    current: page
  }
}

/**
 * 当方法里面的参数发生改变时 就会触发此方法
 */
watchEffect(() => {
  listPageData();
})
//初始化调用
onMounted(() => {
  listPageData();
})

</script>
